#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : Leiyh
# @File : logger_tool.py
import logging


class Logger(object):
    level_relations = {
        'notset':logging.NOTSET,
        'debug': logging.DEBUG,
        'info': logging.INFO,
        'warning': logging.WARNING,
        'error': logging.ERROR,
        'crit': logging.CRITICAL
    }

    def __init__(self, filename, filemode='w', level='notset',
                 format='%(asctime)s - %(levelname)s: %(message)s'):
        logger = logging.getLogger()
        logger.setLevel(level=self.level_relations.get(level))
        filehandle = logging.FileHandler(filename,filemode)
        formatter = logging.Formatter(format)
        filehandle.setFormatter(formatter)
        logger.addHandler(filehandle)


    def debug(self, msg):
        logging.debug(msg)

    def info(self, msg):
        logging.info(msg)

    def warning(self, msg):
        logging.warning(msg)

    def error(self, msg):
        logging.error(msg)

    def critical(self, msg):
        logging.critical(msg)


if __name__ == '__main__':
    logger = Logger('all.log', level='info')
    logger.info("Start print log")
    logger.debug("Do something")
    logger.warning("Something maybe fail")
    logger.error("error print log")